package com.hyt.it.ogt.kq.service.gov.feign.ks;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.core.exception.RemoteRequestException;
import com.hyt.it.ogt.kq.service.gov.feign.ks.model.KwExamCandidateVO;
import com.hyt.it.ogt.kq.service.gov.feign.ks.model.KwExamCollectConfigVO;
import com.hyt.it.ogt.kq.service.gov.feign.ks.model.KwExamVO;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

/**
 * 考试客户端熔断器
 * 
 * @author chengxh
 * @since 2021-11-23
 */
@Component
@Slf4j
public class KsFallbackFactoryClientHystrix implements FallbackFactory<KsFallbackFactoryClient> {
    @Override
    public KsFallbackFactoryClient create(Throwable throwable) {
        log.error("#考试客户端熔断", throwable);
        return new KsFallbackFactoryClient() {
            @Override
            public ApiResponse<KwExamCollectConfigVO> getExamCollectConfig(String examId) {
                log.error("查询考试采集项配置熔断 {}", examId, throwable);
                throw new RemoteRequestException(43340115, "查询考试采集项配置错误");
            }

            @Override
            public ApiResponse<Page<KwExamCandidateVO>> pageCandidateInfo(String examId, int current, int size) {
                log.info("查询考试学生的信息熔断 {} {} {}####", examId, current, size, throwable);
                return null;
            }

            @Override
            public ApiResponse<List<KwExamVO>> listCurrentExam(String officeId, String deptId) {
                log.info("查询当前考试列表熔断 {} {} ####", officeId, deptId, throwable);
                return null;
            }

            @Override
            public ApiResponse<List<KwExamVO>> listDeptIdsExam(String officeId, Set<String> deptIds) {
                log.error("查询当前部门权限下的考试列表熔断 {} {} ####", officeId, deptIds, throwable);
                throw new RemoteRequestException(43340802, "获取部门权限下考试列表失败", "officeId:{},deptIds:{}", officeId, deptIds);
            }

            @Override
            public ApiResponse<KwExamVO> exam(String officeId, String deptId, String examId) {
                log.info("查询当前考试熔断 {} {} {} ####", officeId, deptId, examId, throwable);
                return null;
            }
        };
    }
}
